<?php

namespace app\api\logic\page;

use think\facade\Request;
use app\common\repository\user\R as UserRRepository;
use app\common\repository\book\R as BookRRepository;
use app\common\repository\article\R as ArticleRRepository;
use app\common\repository\promote\R as PromoteRRepository;

class Book
{
    public function __construct(
        UserRRepository $userRRepository,
        BookRRepository $bookRRepository,
        ArticleRRepository $articleRRepository,
        PromoteRRepository $promoteRRepository
    )
    {
        $this->userRRepository = $userRRepository;
        $this->bookRRepository = $bookRRepository;
        $this->articleRRepository = $articleRRepository;
        $this->promoteRRepository = $promoteRRepository;
    }

    public function info()
    {
        $bookId = Request::param('id');
        if (!$bookId) {
            return ['done' => false, 'code' => config('code.common.paramsRequire')];
        }
        $user = $this->userRRepository->getUserByBookId($bookId);
        $book = $this->bookRRepository->getBook(['id' => $bookId]);
        $mostViewArticles = $this->articleRRepository->getMostViewArticles();
        $promotes = $this->promoteRRepository->getPromotes();
        return ['data' => ['user' => $user, 'book' => $book, 'mostViewArticles' => $mostViewArticles, 'promotes' => $promotes]];
    }
}
